package com.wocao;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.boot.test.context.SpringBootTest;
//代码生成器
@SpringBootTest
public class MyGenerator {

    //TODO 数据源配置
    private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
            .Builder("jdbc:mysql://localhost:3306/wisdom-community",
            "root",
            "root")
            .dbQuery(new MySqlQuery());

    //TODO 输出路径
    private static final String outputDir =
            //项目根+目录
            System.getProperty("user.dir") + "/src/main/java";
    //TODO 包名配置
    private static final String parent = "com.wocao";                /*父包名*/
    private static final String xml = "mapper.xml";  /*xml包名*/
    //TODO 作者
    private static final String author = "枣核";

    public static void main(String[] args) {

        FastAutoGenerator.create(DATA_SOURCE_CONFIG)
                //TODO 全局配置
                .globalConfig(builder -> {
                    builder
                            .author(author)         /*设置作者*/
                            .outputDir(outputDir)   /*指定输出目录*/
//                            .enableSpringdoc()      /*生成Springdoc注解*/
//                             .enableSwagger()       /*开启 swagger 模式*/
                            .disableOpenDir();      /*禁止打开输出目录*/
                })
                //TODO 包配置
                .packageConfig(builder -> {
                    //设置父包名 builder.parent("com.guio");
                    builder
                            .parent(parent)
                            .xml(xml)
                    ;
                })
                //TODO 策略
                .strategyConfig(builder -> {
                    //设置需要生成的表名
                    builder.addInclude("zy_like")
                            .controllerBuilder().enableFileOverride().enableRestStyle()
                            //service策略
                            .serviceBuilder()
                            .enableFileOverride()
                            .formatServiceFileName("%sService"/* 格式化Service命名 */)
                            //实体类策略
                            .entityBuilder()
                            .enableFileOverride()
                            .enableLombok()/*实体类lombok注解*/
                            //mapper策略
                            .mapperBuilder()
                            .enableFileOverride();
                })
                //TODO 引擎
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}

/*导包

<!--lombok-->
        <dependency>
            <groupId>de.lars-sh</groupId>
            <artifactId>lombok-annotations</artifactId>
            <version>1.18.28</version>
        </dependency>

        <!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
        </dependency>

        <!--整合myBatis-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.4.1</version>
        </dependency>

        <!--mybatis-plus-generator-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.5.4.1</version>
        </dependency>

        <!--freemarker模板引擎-->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.32</version>
        </dependency>

*/
